package de.muahd.saga.services.core.impl;


import static org.springframework.data.jpa.domain.Specifications.*;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import de.muahd.saga.common.model.Customer;
import de.muahd.saga.services.core.api.CustomerService;
import de.muahd.saga.services.core.impl.repository.CustomerRepository;
import de.muahd.saga.services.core.impl.repository.specifications.CustomerSpecifications;

@Service
@Transactional
public class CustomerServiceImpl implements CustomerService {
	
	@Autowired
	private CustomerRepository customerRepository;
	
	public void saveCustomer(Customer customer) {
		customerRepository.save(customer);
	}
	
	public Customer findByLastName(String lastname) {
		return this.customerRepository.findByLastname(lastname);
	}
	
	public List<Customer> findByFirstName(String firstName) {
		List<Customer> customer = customerRepository.findAll(where(CustomerSpecifications.firstNameEquals(firstName)));
		return customer;
	}
	
	
	public CustomerRepository getCustomerRepository() {
		return customerRepository;
	}

	public void setCustomerRepository(CustomerRepository customerRepository) {
		this.customerRepository = customerRepository;
	}

	@Override
	public List<Customer> findAll() {
		return customerRepository.findAll();
	}
	
	
}
